#pragma once

#include <gofcl_usbfs_deplen.h>
#include <gofcl_usbfs_ep_r.h>

typedef enum {
	USBFS_MCPF_1_PACKET_PER_FRAME = 1,
	USBFS_MCPF_2_PACKET_PER_FRAME = 2,
	USBFS_MCPF_3_PACKET_PER_FRAME = 3,
	USBFS_RXDPID_DATA0 = 0,
	USBFS_RXDPID_DATA1 = 2,
	USBFS_STPCNT_0_SETUP_PACKET = 0,
	USBFS_STPCNT_1_SETUP_PACKET = 1,
	USBFS_STPCNT_2_SETUP_PACKET = 2,
	USBFS_STPCNT_3_SETUP_PACKET = 3,
} usbfs_mcpf_rxdpid_stpcnt_e;

typedef struct {
	u32_s total_size : 19;
	u32_s pkt_nums : 10;
	usbfs_mcpf_rxdpid_stpcnt_e pid_nums : 2;
	u32_s : 1;
} usbfs_deplen_expl_s;

_Static_assert(sizeof(usbfs_deplen_expl_s) == 4,
	       "Struct usbfs_deplen_expl_s defined error!");

static inline void usbfs_set_trans_len(usbfs_ep_re io_r, usbfs_ep_rre ep_rr,
				       usbfs_deplen_expl_s deplen) {
	union {
		usbfs_deplen_expl_s e;
		usbfs_deplen_s d;
	} du = {
		.e = deplen,
	};
	usbfs_wreg_deplen_s(io_r, ep_rr, du.d);
}

static inline usbfs_deplen_expl_s usbfs_get_trans_len(usbfs_ep_re io_r,
						      usbfs_ep_rre ep_rr) {
	union {
		usbfs_deplen_expl_s e;
		usbfs_deplen_s d;
	} du = {
		.d = usbfs_rreg_deplen_s(io_r, ep_rr),
	};
	return du.e;
}
